# Compiles and creates a single canonical file for information about individual users
# For each username (key), finds:
# 	first edit (cohort)
#	last edit (tenure)
#	Total edits
#	Edits by namespace
# 
# The input files for this are the extracted edit data with namespace included, processed with the addtenure script.
#
# The output files will be lists of (username, entry year, total edits, main edits, talk edits, user edits, user talk edits, project edits, project talk edits, etc (the listing order of edits by namespace follows the numeric keys of namespaces (available online) in increasing order)
# Example row:
# UserGuy21	2007-03-10T03:32:59Z	2007-03-24T05:11:19Z	1000	300	300	100	100	50	50	50	50	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0
#
# These output files can be concatenated and sorted to create a correct total listing of all user data.
# 
# Note that this script will fork a thread to process each file individually; it is safest to not run it with a directory argument that contains 
# much more files than threads it can fork. For example, split the files up between a few directories and run them separately. The smart 
# thing to do here would to implement a fake thread pool with a semaphore where the initial value is the size of pool, but 
# not clear if the threading semaphore construction would be good for supporting this.

import os
import sys
import threading
import datetime

def main():

	global namespaces = ["main", "talk", "user", "user talk", "project", "project talk",
		"file", "file talk", "mediawiki", "mediawiki talk", "template", "template talk", "help", "help talk",
		"category", "category talk", "portal", "portal talk", "book", "book talk", "course", "course talk",
		"institution", "institution talk"]
	
	inputDir = sys.argv[1]
	outputDir = sys.argv[2]

class UserDataThread(threading.Thread):

	def __init__(self, inputFilePath, outputFilePath):
		threading.Thread.__init__(self)
		self.inputFilePath = inputFilePath
		self.outputFilePath = outputFilePath

	def run(self):
		extract(inputFilePath, outputFilePath)


def extract(inputFilePath, outputFilePath):
	
	inputFileHandle = open(inputFilePath, 'r')
	outputFileHandle = open(outputFilePath, 'a+')


	for line in inputFileHandle:
		
		tokens = line.split('\t')

		
	inputFileHandle.close()
	outputFileHandle.close()

def initEdits():
	edits = {}
	edits['total'] = 0
	for namespace in namespaces:
		edits[namespace] = 0
	return edits
